package com.example.tests.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.*;

import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import com.example.tests.logic.AlertHelper;
import com.example.tests.pages.MyPageFactory;

public abstract class MainTemplate extends AnyPage {
	@FindBy(xpath = "//nav//li[2]/a")
	protected WebElement profileLink;
	@FindBy(xpath = "//nav//li[3]/a")
	protected WebElement userManagementLink;
	@FindBy(xpath = "//nav//li[1]/a")
	protected WebElement homeLink;
	@FindBy(xpath = "//div[ @class = 'center' ]/nav//li/a")
	protected List<WebElement> navLinks;
	@FindBy( xpath = "//div[ @class = 'content' ]" )
	protected List<WebElement> content;
	
	public ProfilePage goProfilePage() {
		wait_().until(visibilityOf(profileLink)).click();
		return MyPageFactory.getPage(driver,ProfilePage.class);
	}
	
	public UserManagementPage goUserManagementPage() {
		userManagementLink.click();
		return MyPageFactory.getPage(driver,UserManagementPage.class);
	}
	
	public HomePage goHomePage() {
		homeLink.click();
		return MyPageFactory.getPage(driver,HomePage.class);
	}
	
	public FilmsPage goFilmsPage() {
		homeLink.click();
		return MyPageFactory.getPage(driver,FilmsPage.class);
	}
	
	public void logout() {
		navLinks.get(navLinks.size()-1).click();
		wait_().until(alertIsPresent()).accept();
		
	}
	public String getLogoutAlertText() {
		navLinks.get(navLinks.size()-1).click();
		return new AlertHelper(driver).closeAlertAndGetItsText();
	}
	public boolean IsLoginSuccessfull() {
		return 	navLinks.get(navLinks.size()-1).isDisplayed();    
	}
	
}